const { Service } = require("egg");

class DeptService extends Service {
    /**
     * 获取部门列表
     */
    async readList() {
        let sql = "select * from dept";
        let res = await this.app.mysql.query(sql);
        return res;
    }

    /**
     * 根据部门名称，获取部门信息
     * @param {string} name 部门名称
     */
    async findByName(name) {
        let sql = "select * from dept where name = ?";
        let params = [name];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    /**
     * 添加一个部门
     * @param {string} name 部门名称
     */
    async create(name) {
        let sql = "insert into dept (name) values (?)";
        let params = [name];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = DeptService;
